import {observable,action} from 'mobx';
import {login,UserInfo,gitlogin} from '../../services/user';

export default class User{
    @observable isLogin:boolean = false;

    @action 
    getLoginStatus = () => {
        const token = window.localStorage.getItem('token');
        if(token && token.split('.').length === 3){
            this.isLogin = true;
        }else{
            this.isLogin = false;
        }
    }
    
    @action
    login = async (params:UserInfo) => {
        let res = await login(params);
        if(res.data.code === 1){
            window.localStorage.setItem('token',res.data.data.token);
            return res
        }
    }

    @action
    gitlogin = async () => {
        let res = await gitlogin();
        if(res.data.code === 1){
            window.location.href=res.data.data.url;
        }
    }
}